問題描述
python中的握手失敗(_ssl.c:590) (HandShake Failure in python(_ssl.c:590))
當我執行以下行時,
req = urllib2.Request(requestwithtoken)
self.response = urllib2.urlopen(req,self.request).read()
我得到以下異常:
SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:590)
問題是我可以通過使用 <代碼>捲曲</代碼>。在檢索令牌的過程中,所有證書都經過驗證。反過來,通過使用生成的令牌,我無法連接到服務。我在嘗試時遇到上述錯誤。這可能是什麼原因?
參考解法
方法 1:
I was having the same issue. It's probably because your remote server requests cipher that isn't supported by urllib2. I think there're two solutions possible:
Enable your specific cipher in
urllib
. I think you can also enable all ciphers supported (see the very bottom of the page) but rather check which one you're using withcurl
as shown in the link above.Install
requests
with extra security packages using:pip install requests[security]
. It's further discussed in this requests issue on github.
I did the second option and it worked for me.
方法 2:
I also had the same issue. Check which version of requests you are using.
import requests
print requests.__version__
If the version is 2.18.4, you should try downgrading to version 2.11.1. I did this, and it fixed my problem. To do this, issue the following commands in the terminal
pip uninstall requests
pip install requests==2.11.1
Hope this helps.
(by Bharathi Kodeeswaran、martin、CPSuperstore)